```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Servlet技术全解 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f9fafb;
            color: #374151;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-radius: 0.5rem;
        }
        .highlight {
            position: relative;
        }
        .highlight::before {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 4px;
            background-color: #4f46e5;
            border-radius: 4px 0 0 4px;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-7xl mx-auto">
            <div class="text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6 serif">Servlet 核心技术解析</h1>
                <p class="text-xl md:text-2xl max-w-3xl mx-auto leading-relaxed">
                    Java Web开发的基础组件，理解Servlet是掌握现代Web开发的关键一步
                </p>
                <div class="mt-8 flex justify-center space-x-4">
                    <a href="#what-is-servlet" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-lg hover:bg-gray-100 transition duration-300">
                        <i class="fas fa-book-open mr-2"></i>开始学习
                    </a>
                    <a href="#mermaid-chart" class="px-6 py-3 bg-indigo-700 text-white font-medium rounded-lg hover:bg-indigo-800 transition duration-300">
                        <i class="fas fa-project-diagram mr-2"></i>知识图谱
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- What is Servlet -->
        <section id="what-is-servlet" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-server text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">什么是Servlet</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <p class="text-gray-700 leading-relaxed mb-6">
                        Servlet是Java平台上的一种用于开发Web应用程序的组件。它是基于Java技术的服务器端程序，主要用于处理客户端发起的HTTP请求并生成相应的HTTP响应。
                    </p>
                    <p class="text-gray-700 leading-relaxed mb-6">
                        Servlet是一种基于Java的API，它运行在支持Servlet规范的Web服务器上，如Apache Tomcat、Jetty等。Servlet通常被用于创建动态的、可交互的Web应用程序，可以处理各种类型的HTTP请求，包括GET、POST、PUT、DELETE等。
                    </p>
                </div>
                <div class="rounded-xl overflow-hidden shadow-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097016747-d24e5eb2-95b7-4a80-9424-98a68917cd28.png" alt="Servlet架构图" class="w-full h-auto">
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">Servlet的主要特点和优势</h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <div class="flex items-center justify-center h-6 w-6 rounded-full bg-indigo-100 text-indigo-600">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                            </div>
                            <div class="ml-3">
                                <p class="text-gray-700 font-medium">跨平台性</p>
                                <p class="text-gray-600 text-sm">由于Java语言的跨平台特性，Servlet可以在各种操作系统上运行，并且与服务器无关。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <div class="flex items-center justify-center h-6 w-6 rounded-full bg-indigo-100 text-indigo-600">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                            </div>
                            <div class="ml-3">
                                <p class="text-gray-700 font-medium">灵活性</p>
                                <p class="text-gray-600 text-sm">Servlet可以与各种服务器端技术和框架集成，如JSP、Spring等，可以灵活地处理各种类型的业务逻辑。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <div class="flex items-center justify-center h-6 w-6 rounded-full bg-indigo-100 text-indigo-600">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                            </div>
                            <div class="ml-3">
                                <p class="text-gray-700 font-medium">安全性</p>
                                <p class="text-gray-600 text-sm">Servlet提供了安全性机制，可以对请求进行验证和授权，保护Web应用程序的安全。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <div class="flex items-center justify-center h-6 w-6 rounded-full bg-indigo-100 text-indigo-600">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                            </div>
                            <div class="ml-3">
                                <p class="text-gray-700 font-medium">高性能</p>
                                <p class="text-gray-600 text-sm">Servlet在处理HTTP请求和响应时具有高效性能，能够处理大量的并发请求。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 mt-1">
                                <div class="flex items-center justify-center h-6 w-6 rounded-full bg-indigo-100 text-indigo-600">
                                    <i class="fas fa-check text-xs"></i>
                                </div>
                            </div>
                            <div class="ml-3">
                                <p class="text-gray-700 font-medium">可扩展性</p>
                                <p class="text-gray-600 text-sm">Servlet提供了丰富的API和扩展机制，可以方便地编写复杂的Web应用程序，并且易于维护和扩展。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Creating Servlet -->
        <section id="creating-servlet" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-code text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">创建Servlet</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="rounded-xl overflow-hidden shadow-lg mb-6">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097091327-ab0f061f-d5f2-4a7f-bdde-bc9c0ace736a.png" alt="创建Servlet流程" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-6 card-hover">
                        <div class="p-6">
                            <h3 class="text-xl font-semibold mb-4 text-indigo-600">创建Servlet的步骤</h3>
                            <ol class="list-decimal pl-5 space-y-3 text-gray-700">
                                <li><span class="font-medium">创建一个Java Web项目</span>：在IDE中创建一个新的Java Web项目，比如使用Eclipse或IntelliJ IDEA等。选择创建一个Dynamic Web Project。</li>
                                <li><span class="font-medium">编写Servlet类</span>：在项目中创建一个Java类，继承自javax.servlet.http.HttpServlet类，并重写doGet()或doPost()方法。</li>
                                <li><span class="font-medium">配置Servlet映射</span>：在web.xml文件中配置Servlet的映射关系，指定Servlet的URL模式以及对应的Servlet类。</li>
                                <li><span class="font-medium">部署项目到Servlet容器</span>：将项目打包成WAR文件，或者直接复制项目文件到Servlet容器的webapps目录中。</li>
                                <li><span class="font-medium">启动Servlet容器</span>：启动已安装的Servlet容器，比如运行Tomcat的启动脚本。</li>
                                <li><span class="font-medium">访问Servlet应用程序</span>：在浏览器中输入Servlet的URL即可看到输出结果。</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="code-block p-6 rounded-xl">
                    <div class="flex items-center text-gray-300 mb-4">
                        <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                        <span class="ml-2 text-sm">HelloWorldServlet.java</span>
                    </div>
                    <pre class="text-sm overflow-x-auto"><code class="language-java">import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, 
            HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        response.getWriter().println("&lt;html&gt;&lt;body&gt;&lt;h1&gt;Hello, World!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;");
    }
}</code></pre>
                </div>
                
                <div class="code-block p-6 rounded-xl">
                    <div class="flex items-center text-gray-300 mb-4">
                        <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                        <span class="ml-2 text-sm">web.xml</span>
                    </div>
                    <pre class="text-sm overflow-x-auto"><code class="language-xml">&lt;web-app&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.example.HelloWorldServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
&lt;/web-app&gt;</code></pre>
                </div>
            </div>
        </section>

        <!-- Servlet Lifecycle -->
        <section id="servlet-lifecycle" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-recycle text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Servlet生命周期</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="rounded-xl overflow-hidden shadow-lg">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097236749-9171d4da-229d-4e66-a0ea-e0addda6d21d.png" alt="Servlet生命周期" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">Servlet的生命周期包括以下几个阶段</h3>
                        <div class="space-y-6">
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">1. 加载阶段（Loading）</h4>
                                <p class="text-gray-700">当Servlet容器启动时，会加载并初始化Servlet。在加载阶段，Servlet容器会创建Servlet类的一个实例，并调用其init()方法来执行一些初始化操作，例如加载配置文件、建立数据库连接等。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">2. 初始化阶段（Initialization）</h4>
                                <p class="text-gray-700">在Servlet加载后，Servlet容器会调用其init()方法，对Servlet进行初始化。开发者可以重写init()方法，进行一些自定义的初始化操作。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">3. 请求处理阶段（Request Handling）</h4>
                                <p class="text-gray-700">一旦Servlet初始化完成，它就可以接收和处理客户端的请求。每当有请求到达Servlet时，Servlet容器会创建一个新的线程来处理该请求。Servlet容器调用Servlet的service()方法来处理请求。根据请求类型的不同，service()方法会调用doGet()、doPost()等方法来响应请求。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">4. 销毁阶段（Destruction）</h4>
                                <p class="text-gray-700">当Servlet容器关闭或者在Web应用程序被卸载时，Servlet将被销毁。在销毁阶段，Servlet容器会调用Servlet的destroy()方法来执行一些清理操作，例如释放资源、关闭数据库连接等。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Servlet Structure & API -->
        <section id="servlet-structure" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-sitemap text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Servlet的基本结构和API</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                    <div class="rounded-xl overflow-hidden mb-6">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097364099-39520dd6-808e-46d5-8a50-63201877f731.png" alt="Servlet API结构" class="w-full h-auto">
                    </div>
                    <p class="text-gray-700 mb-4">
                        Servlet是Java编写的服务器端程序，用于处理客户端请求并生成响应。Servlet通常用于构建动态的Web应用程序。
                    </p>
                    <div class="space-y-4">
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">Servlet接口</h4>
                            <p class="text-gray-700">所有Servlet类必须实现的接口，定义了Servlet的生命周期方法，包括init()、service()和destroy()。</p>
                        </div>
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">GenericServlet类</h4>
                            <p class="text-gray-700">Servlet接口的抽象实现类，简化了Servlet的开发。开发者可以继承GenericServlet类来实现自己的Servlet。</p>
                        </div>
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">HttpServlet类</h4>
                            <p class="text-gray-700">GenericServlet的子类，专门用于处理HTTP请求和响应。提供了doGet()、doPost()、doPut()、doDelete()等方法来处理不同类型的HTTP请求。</p>
                        </div>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">核心API组件</h3>
                    <div class="space-y-6">
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">Servlet生命周期方法</h4>
                            <ul class="list-disc pl-5 space-y-2 text-gray-700">
                                <li><span class="font-medium">init(ServletConfig config)</span>：在Servlet被加载后立即调用，用于执行初始化操作。</li>
                                <li><span class="font-medium">service(ServletRequest request, ServletResponse response)</span>：用于处理客户端的请求并生成响应。</li>
                                <li><span class="font-medium">destroy()</span>：在Servlet被销毁前调用，用于执行清理操作。</li>
                            </ul>
                        </div>
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">ServletConfig和ServletContext</h4>
                            <p class="text-gray-700">ServletConfig对象用于获取Servlet的配置信息，如初始化参数、Servlet名称等。ServletContext对象用于获取Web应用程序的上下文信息。</p>
                        </div>
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">HttpServletRequest和HttpServletResponse</h4>
                            <p class="text-gray-700">HttpServletRequest封装了客户端的HTTP请求信息，HttpServletResponse用于生成HTTP响应并将响应发送给客户端。</p>
                        </div>
                        <div class="highlight pl-4">
                            <h4 class="font-bold text-lg text-gray-800 mb-2">Servlet注解</h4>
                            <p class="text-gray-700">通过使用@WebServlet、@WebInitParam等注解，可以在Servlet类中声明Servlet的URL映射和初始化参数，而不必使用web.xml文件进行配置。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Servlet Request Processing -->
        <section id="request-processing" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-exchange-alt text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Servlet请求处理</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="rounded-xl overflow-hidden shadow-lg">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097425703-3422ffc9-2cc8-461a-bc15-e01cb77ef92e.png" alt="Servlet请求处理流程" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">Servlet请求处理流程</h3>
                        <ol class="list-decimal pl-5 space-y-3 text-gray-700">
                            <li><span class="font-medium">Servlet容器接收请求</span>：当客户端发送HTTP请求到Web服务器时，Servlet容器负责接收请求并确定要调用哪个Servlet来处理请求。</li>
                            <li><span class="font-medium">Servlet实例化和初始化</span>：Servlet容器检查是否已有该Servlet的实例。如果没有，则实例化Servlet，并调用其init()方法进行初始化。</li>
                            <li><span class="font-medium">创建请求和响应对象</span>：Servlet容器为每个请求创建一个HttpServletRequest对象和一个HttpServletResponse对象。</li>
                            <li><span class="font-medium">service()方法调用</span>：Servlet容器调用Servlet的service()方法，并将请求和响应对象作为参数传递。</li>
                            <li><span class="font-medium">请求处理</span>：Servlet根据请求类型和参数执行相应的业务逻辑。</li>
                            <li><span class="font-medium">Servlet销毁</span>：当Servlet容器关闭或重启时，会调用Servlet的destroy()方法进行清理。</li>
                            <li><span class="font-medium">HTTP响应发送</span>：Servlet容器将响应内容发送给客户端。</li>
                        </ol>
                    </div>
                </div>
            </div>
        </section>

        <!-- Servlet URL Mapping -->
        <section id="url-mapping" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-link text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Servlet URL映射</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="rounded-xl overflow-hidden shadow-lg">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097698879-27ff32b1-0a22-4608-b845-94b822381ae8.png" alt="Servlet URL映射" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">URL映射方式</h3>
                        <div class="space-y-4">
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">1. web.xml配置</h4>
                                <div class="code-block p-4 rounded-lg mb-4">
                                    <pre class="text-sm overflow-x-auto"><code class="language-xml">&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/myservlet&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;</code></pre>
                                </div>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">2. 注解方式</h4>
                                <div class="code-block p-4 rounded-lg">
                                    <pre class="text-sm overflow-x-auto"><code class="language-java">@WebServlet("/myservlet")
public class MyServlet extends HttpServlet {
    // Servlet代码
}</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover mb-8">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600">Servlet参数传递</h3>
                <div class="rounded-xl overflow-hidden mb-6">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097565437-c9c2d54b-96f0-4b99-9a06-2a46de04a0cc.png" alt="Servlet参数传递" class="w-full h-auto">
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">URL参数传递</h4>
                        <p class="text-gray-700">客户端可以通过URL的查询字符串传递参数给Servlet。例如，对于URL模式"/myservlet?param1=value1&param2=value2"，可以通过HttpServletRequest对象的getParameter()方法获取参数值。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">表单提交参数</h4>
                        <p class="text-gray-700">当客户端通过表单提交数据时，可以将表单中的参数传递给Servlet。Servlet可以通过HttpServletRequest对象的getParameter()方法获取表单参数的值。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">路径参数</h4>
                        <p class="text-gray-700">使用RESTful风格的URL设计，可以将参数直接包含在URL的路径中。例如，URL模式"/myservlet/{param}"，Servlet可以通过HttpServletRequest对象获取路径参数的值。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">隐藏字段传递</h4>
                        <p class="text-gray-700">在HTML表单中使用隐藏字段(hidden field)可以将数据传递给Servlet，Servlet可以通过HttpServletRequest对象获取隐藏字段的值。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Cookie -->
        <section id="cookie" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-cookie-bite text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Cookie</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="rounded-xl overflow-hidden shadow-lg">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709097821831-5f338a12-7e9e-4e9f-a646-d1f1e87965bb.png" alt="Cookie机制" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">Cookie简介</h3>
                        <p class="text-gray-700 mb-4">
                            Cookie是存储在用户计算机上的小型文本文件，由Web服务器通过浏览器发送给用户，并存储在用户的硬盘上。它通常用于跟踪用户的会话状态、记录用户的偏好设置以及实现个性化的用户体验。
                        </p>
                        <div class="space-y-4">
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">存储位置</h4>
                                <p class="text-gray-700">Cookie存储在用户的浏览器中，可以在用户的计算机上长时间保存。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">用途</h4>
                                <p class="text-gray-700">Cookie主要用于在Web浏览器和服务器之间传递数据，通常用于实现用户状态的跟踪、会话管理、用户偏好设置等功能。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">结构</h4>
                                <p class="text-gray-700">每个Cookie都是一个键值对，包含了一些信息和相关的元数据。常见的元数据包括Cookie的名称、值、过期时间、作用域等。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover mb-8">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600">使用Cookie的基本步骤</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">1. 创建Cookie</h4>
                        <p class="text-gray-700">服务器通过HTTP响应头将Cookie发送给客户端。可以通过设置Set-Cookie头来创建新的Cookie，并将其发送到客户端浏览器。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">2. 接收Cookie</h4>
                        <p class="text-gray-700">客户端浏览器接收到Cookie后，会将其存储在本地。在后续的HTTP请求中，客户端浏览器会自动将相关的Cookie信息包含在请求头中发送给服务器。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">3. 读取Cookie</h4>
                        <p class="text-gray-700">服务器通过HTTP请求头中的Cookie字段来读取客户端发送的Cookie信息。可以使用HttpServletRequest对象的getCookies()方法来获取所有的Cookie信息。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">4. 删除Cookie</h4>
                        <p class="text-gray-700">服务器可以通过设置Cookie的过期时间为0来删除Cookie，使其立即失效。也可以通过设置Cookie的路径为当前路径以外来使其失效。</p>
                    </div>
                </div>
            </div>
            
            <div class="code-block p-6 rounded-xl">
                <div class="flex items-center text-gray-300 mb-4">
                    <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                    <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                    <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                    <span class="ml-2 text-sm">CookieDemo.java</span>
                </div>
                <pre class="text-sm overflow-x-auto"><code class="language-java">import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/CookieDemo")
public class CookieDemo extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        
        // 创建一个Cookie对象
        Cookie cookie = new Cookie("username", "john_doe");
        
        // 设置Cookie的有效期为一天（以秒为单位）
        cookie.setMaxAge(24 * 60 * 60);
        
        // 将Cookie添加到响应头中
        response.addCookie(cookie);
        
        // 输出页面内容
        response.getWriter().println("&lt;html&gt;&lt;body&gt;");
        response.getWriter().println("&lt;h2&gt;Cookie Demo&lt;/h2&gt;");
        response.getWriter().println("&lt;p&gt;Cookie 'username' has been set.&lt;/p&gt;");
        response.getWriter().println("&lt;/body&gt;&lt;/html&gt;");
    }
}</code></pre>
            </div>
        </section>

        <!-- Session -->
        <section id="session" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-user-clock text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Session</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <div class="rounded-xl overflow-hidden shadow-lg">
                        <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1709098019000-d8467650-0a39-407d-9691-c7550158e2c8.png" alt="Session机制" class="w-full h-auto">
                    </div>
                </div>
                <div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">Session简介</h3>
                        <p class="text-gray-700 mb-4">
                            Session是Web应用程序中的一种机制，用于在服务器端跟踪用户的状态信息。它允许服务器为每个用户维护特定于用户的信息，并且这些信息在用户访问应用程序的不同页面之间保持持久性。
                        </p>
                        <div class="space-y-4">
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">状态保持</h4>
                                <p class="text-gray-700">Session允许在不同的HTTP请求之间保持状态信息。当用户与服务器建立会话时，服务器会为该用户创建一个唯一的会话ID。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">数据存储</h4>
                                <p class="text-gray-700">在会话期间，服务器可以将数据存储在Session对象中。这些数据通常是用户的登录信息、购物车内容、用户首选项等。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">会话过期</h4>
                                <p class="text-gray-700">Session可以设置过期时间，一旦会话超时，服务器将删除该会话并释放相应的资源。</p>
                            </div>
                            <div class="highlight pl-4">
                                <h4 class="font-bold text-lg text-gray-800 mb-2">安全性</h4>
                                <p class="text-gray-700">Session的会话ID是通过Cookie或URL重写发送给客户端的，在传输过程中可以使用SSL等加密技术进行保护。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover mb-8">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600">Session的基本使用方法</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">创建Session</h4>
                        <p class="text-gray-700">当用户首次访问Web应用程序时，服务器会创建一个Session对象，并为该用户分配一个唯一的会话ID。</p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">存储数据</h4>
                        <p class="text-gray-700">在Session对象中，可以使用setAttribute()方法存储数据。例如：<code class="bg-gray-100 px-1 rounded">session.setAttribute("username", "john_doe");</code></p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">获取数据</h4>
                        <p class="text-gray-700">可以使用getAttribute()方法从Session对象中检索存储的数据。例如：<code class="bg-gray-100 px-1 rounded">String username = (String) session.getAttribute("username");</code></p>
                    </div>
                    <div class="highlight pl-4">
                        <h4 class="font-bold text-lg text-gray-800 mb-2">销毁Session</h4>
                        <p class="text-gray-700">当用户退出或会话过期时，服务器会销毁Session对象，并释放相关资源。</p>
                    </div>
                </div>
            </div>
            
            <div class="code-block p-6 rounded-xl">
                <div class="flex items-center text-gray-300 mb-4">
                    <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                    <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                    <div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
                    <span class="ml-2 text-sm">LoginServlet.java</span>
                </div>
                <pre class="text-sm overflow-x-auto"><code class="language-java">import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取用户提交的用户名和密码
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        // 模拟验证用户名和密码的逻辑
        if ("admin".equals(username) && "password".equals(password)) {
            // 获取或创建用户的Session对象
            HttpSession session = request.getSession(true);
            // 将用户名存储到Session中
            session.setAttribute("username", username);
            // 重定向到欢迎页面
            response.sendRedirect("welcome.jsp");
        } else {
            // 用户名或密码错误，重定向到登录页面
            response.sendRedirect("login.jsp");
        }
    }
}</code></pre>
            </div>
        </section>

        <!-- Mermaid Chart -->
        <section id="mermaid-chart" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="flex-shrink-0 mr-4">
                    <div class="flex items-center justify-center h-12 w-12 rounded-md bg-indigo-500 text-white">
                        <i class="fas fa-project-diagram text-xl"></i>
                    </div>
                </div>
                <h2 class="text-3xl font-bold text-gray-900 serif">Servlet知识图谱</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 card-hover">
                <div class="mermaid">
                    graph TD
                        A[Servlet] --> B[生命周期]
                        A --> C[API结构]
                        A --> D[请求处理]
                        A --> E[会话管理]
                        
                        B --> B1[加载阶段]
                        B --> B2[初始化阶段]
                        B --> B3[请求处理阶段]
                        B --> B4[销毁阶段]
                        
                        C --> C1[Servlet接口]
                        C --> C2[GenericServlet]
                        C --> C3[HttpServlet]
                        C --> C4[ServletConfig]
                        C --> C5[ServletContext]
                        
                        D --> D1[HttpServletRequest]
                        D --> D2[HttpServletResponse]
                        D --> D3[URL映射]
                        D --> D4[参数传递]
                        
                        E --> E1[Cookie]
                        E --> E2[Session]
                        E --> E3[安全机制]
                        
                        style A fill:#4f46e5,color:white
                </div>
            </div>
        </section>

        <!-- Download Section -->
        <section class="bg-indigo-50 rounded-xl p-8 mb-16 text-center">
            <h3 class="text-2xl font-bold text-gray-900 mb-4 serif">下载完整的Servlet思维导图</h3>
            <p class="text-gray-700 mb-6 max-w-2xl mx-auto">
                获取完整的Servlet技术体系思维导图，帮助您系统性地理解和掌握Servlet相关知识。
            </p>
            <a href="https://www.yuque.com/attachments/yuque/0/2023/xmind/21449790/1692788333959-61caaba6-d8de-405d-ac11-3688a5104182.xmind" 
               class="inline-flex items-center px-6 py-3 bg-indigo-600 text-white font-medium rounded-lg hover:bg-indigo-700 transition duration-300">
                <i class="fas fa-download mr-2"></i>下载思维导图
            </a>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white">技术小馆</h3>
                    <p class="mt-2 text-sm">专注于高质量技术内容分享</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-white transition duration-300">
                        <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-8 border-t border-gray-800 text-center text-sm">
                <p>&copy; 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <!-- Scripts -->
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function(e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```